package android.support.v4.os;

import android.view.InputEvent;
import android.view.KeyEvent;

import com.example.auto.ScriptMaker;
import com.example.utils.Logger;

import de.robv.android.xposed.XposedHelpers;

public class EInputEventReceiver extends EHook {
	static final Logger log = Logger.create("input");

	@Override
	public String getClassName() {
		return "android.view.InputEventReceiver";
	}

	@Override
	public void hook() {
		log.d("hook dispatchInputEvent >>>");
		
		// dispatchInputEvent(int seq, InputEvent event)
		// dispatchInputEvent(int seq, InputEvent event)
		XposedHelpers.findAndHookMethod(getClassName(), null, 
				"dispatchInputEvent",
				int.class, InputEvent.class,
				this);
	}

	protected void after(String name, Object[] args, MethodHookParam param) {
		//日志太多
//		log.i("after " + name);
		
		if(name.equals("dispatchInputEvent")) {
			InputEvent event = (InputEvent) args[1];
			ScriptMaker.onInputEvent(event);
			
			if(event instanceof KeyEvent) {
	            KeyEvent ke = (KeyEvent) event;
	            
	            if(ke.getKeyCode() == KeyEvent.KEYCODE_HOME && ke.getAction() == KeyEvent.ACTION_UP) {
	            }
			}
			
//			log.i("input seq=" + args[0] + " event=" + event);
		}
	}
}
